#!/bin/bash -x

(
  sysctl -w net.ipv4.neigh.default.gc_thresh3=4096 || true
  sysctl -w net.ipv4.neigh.default.gc_thresh2=2048 || true
) \
  > /etc/sysctl.d/100-bosh-nats.conf

if [ ! -f /var/vcap/data/nats/auth.json ]; then
   echo "{"authorization": {"token": "f0oBar"}}" > /var/vcap/data/nats/auth.json
fi

chown vcap:vcap /var/vcap/data/nats/auth.json

/usr/bin/openssl x509 -in /var/vcap/jobs/nats/config/nats_director_client_certificate.pem -noout -subject | cut -b 9- | sed -e 's/^ \///' | sed -e 's/\//, /g' > /var/vcap/data/nats/director-subject

/usr/bin/openssl x509 -in /var/vcap/jobs/nats/config/nats_hm_client_certificate.pem -noout -subject | cut -b 9- | sed -e 's/^ \///' | sed -e 's/\//, /g' > /var/vcap/data/nats/hm-subject